class Trie {
public:
    struct node
    {
        bool isFinish = false;
        node *children[26] = { nullptr };
    };

    Trie() {
        root = new node();
    }
    
    void insert(string word) {
        node *cur = root;
        for(int i = 0; i < word.size(); i++)
        {
            int index = word[i] - 'a';
            if(cur->children[index] == nullptr)
                cur->children[index] = new node();
            cur = cur->children[index];
        }
        cur->isFinish = true;
    }
    
    bool search(string word) {
        node *cur = root;
        for(int i = 0; i < word.size(); i++)
        {
            int index = word[i] - 'a';
            if(cur->children[index] == nullptr)
                return false;
            cur = cur->children[index];
        }
        return cur->isFinish;
    }
    
    bool startsWith(string prefix) {
        node *cur = root;
        for(int i = 0; i < prefix.size(); i++)
        {
            int index = prefix[i] - 'a';
            if(cur->children[index] == nullptr)
                return false;
            cur = cur->children[index];
        }
        return true;
    }
private:
    node *root;
};

/**
 * Your Trie object will be instantiated and called as such:
 * Trie* obj = new Trie();
 * obj->insert(word);
 * bool param_2 = obj->search(word);
 * bool param_3 = obj->startsWith(prefix);
 */